<?php
		session_start();		
        require_once('../inc/function.php');		
		include("config.php");	
		if($_SERVER["REQUEST_METHOD"]=="POST")
		{
			$username = addslashes($_POST['name']);
			$password = md5(addslashes($_POST['pass']));
			
			$sql ="SELECT * FROM Customer WHERE email='$username' AND password='$password'";
			$result = mysql_query($sql);
			$count = mysql_num_rows($result);		
			if($count==1)
			{
				session_register("myusername");
				$_SESSION['login_user'] = $username;
				$_SESSION['logged_in'] = true;
				header("location:twitter_serverside.php");
			}
			else
				$error="Your email or password is invalid";
		}
        $searchUrl = "http://search.twitter.com/search.json";
        $results = curl_get($searchUrl, "GET", array('q' => 'New Paltz'));
        //echo $results;
        $ob = json_decode($results);
        //print_r($ob);
        $tweets = $ob->results;
?>
<!DOCTYPE html>
<html lang="en">
<?php include('../inc/head.php'); ?>
<body>	 
	 <?php
	 	if($_SESSION['logged_in']===true) 
			include('../inc/nav2.php');
		else	
	 		include('../inc/nav.php');	 
	 ?>       
        <div class="container">                       
            <div id="contents">
            	                        <h3>Searched for <?=$ob->query?></h3>                       
                                <ul class="unstyled">
                        <? foreach ($tweets as $tweet): ?>
                                          <li id="list_item_<?=$tweet->id?>">
                                                <img src="<?=$tweet->profile_image_url?>" />
                                                <?=$tweet->from_user_name?>
                                                (@<?=$tweet->from_user?>)
                                            <?=$tweet->text?>
                        <br /> <?= html_entity_decode($tweet->source)?>
                                          </li>
                                        <? endforeach; ?>
                                </ul>  
            </div>
      <footer>
        <p>&copy; Company 2012</p>
      </footer>
    </div> <!-- /container -->
    <!-- Le javascript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="../inc/bootstrap/js/jquery.js"></script>
    <script src="../inc/bootstrap/js/bootstrap-min.js"></script>
  </body>
</html>